package com.franklin.validation.core.argument.impl.collection;

import com.franklin.validation.core.annotations.ParamCheck;
import com.franklin.validation.core.annotations.Resolver;
import com.franklin.validation.core.annotations.WebFluxFormDataComponent;
import com.franklin.validation.core.entity.CheckFormEntity;
import com.franklin.validation.core.utils.DataCheckUtil;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Description :
 * Create By: Franklin
 * Date : 2020/6/15 16:44
 */
@Resolver
@WebFluxFormDataComponent
public class SetResolverResult extends CollectionResolverResult<Set> {
    @Override
    public Set onError(CheckFormEntity input) {
        return new HashSet<>();
    }

    @Override
    public Set getResult(CheckFormEntity input) {
        List<String> values = input.getValues();
        ParamCheck paramCheck = input.getParamCheck();
        if (DataCheckUtil.isEmpty(values)){
            return new HashSet();
        }
        if (Number.class.isAssignableFrom(input.getGenericType())){
            return this.parseNumber(input).collect(Collectors.toSet());
        }
        return new HashSet<>(values);
    }
}
